package com.zzzy.controller;




import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.TreeMap;

@Controller
public class HelloController {

    //Logger logger = Logger.getLogger(this.getClass());
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @ResponseBody
    @RequestMapping("/hello")
    public String sayHello(){
        int count = 3/0;
        return "Hello World";
    }


    /**
     * 异常页面控制
     *
     * @param runtimeException
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public @ResponseBody
    Map<String,Object> runtimeExceptionHandler(RuntimeException runtimeException, HttpServletRequest request) {
        logger.error( runtimeException.getMessage(),runtimeException);

        //runtimeException.printStackTrace();
        Map model = new TreeMap();
        model.put("status", false);
        return model;
    }

}
